home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 92 / CDMM92_1.ISO / SOF 2 SDK / sof2sdk-101.msi / _92D6AC311BB48EBA344BBABC89DA6AB0 / _6717FEF82EC542D092ED069F7A87613B < prev    next >
Encoding:
Text File  |  2002-06-05  |  6.3 KB  |  276 lines

  1. // Copyright (C) 2001-2002 Raven Software.
  2. //
  3. // cg_effects.c -- these functions generate localentities, usually as a result
  4. // of event processing
  5.  
  6. #include "cg_local.h"
  7.  
  8. /*
  9. ==================
  10. CG_BubbleTrail
  11.  
  12. Bullets shot underwater
  13. ==================
  14. */
  15. void CG_BubbleTrail( vec3_t start, vec3_t end, float spacing ) {
  16.     vec3_t        move;
  17.     vec3_t        vec;
  18.     float        len;
  19.     int            i;
  20.  
  21.     if ( cg_noProjectileTrail.integer ) {
  22.         return;
  23.     }
  24.  
  25.     VectorCopy (start, move);
  26.     VectorSubtract (end, start, vec);
  27.     len = VectorNormalize (vec);
  28.  
  29.     // advance a random amount first
  30.     i = rand() % (int)spacing;
  31.     VectorMA( move, i, vec, move );
  32.  
  33.     VectorScale (vec, spacing, vec);
  34.  
  35.     for ( ; i < len; i += spacing ) {
  36.         localEntity_t    *le;
  37.         refEntity_t        *re;
  38.  
  39.         le = CG_AllocLocalEntity();
  40.         le->leFlags = LEF_PUFF_DONT_SCALE;
  41.         le->leType = LE_MOVE_SCALE_FADE;
  42.         le->startTime = cg.time;
  43.         le->endTime = cg.time + 1000 + random() * 250;
  44.         le->lifeRate = 1.0 / ( le->endTime - le->startTime );
  45.  
  46.         re = &le->refEntity;
  47.         re->shaderTime = cg.time / 1000.0f;
  48.  
  49.         re->reType = RT_SPRITE;
  50.         re->rotation = 0;
  51.         re->radius = 3;
  52.         re->customShader = cgs.media.waterBubbleShader;
  53.         re->shaderRGBA[0] = 0xff;
  54.         re->shaderRGBA[1] = 0xff;
  55.         re->shaderRGBA[2] = 0xff;
  56.         re->shaderRGBA[3] = 0xff;
  57.  
  58.         le->color[3] = 1.0;
  59.  
  60.         le->pos.trType = TR_LINEAR;
  61.         le->pos.trTime = cg.time;
  62.         VectorCopy( move, le->pos.trBase );
  63.         le->pos.trDelta[0] = crandom()*5;
  64.         le->pos.trDelta[1] = crandom()*5;
  65.         le->pos.trDelta[2] = crandom()*5 + 6;
  66.  
  67.         VectorAdd (move, vec, move);
  68.     }
  69. }
  70.  
  71.  
  72. void CG_TestLine( vec3_t start, vec3_t end, int time, unsigned int color, int radius) 
  73. {
  74.     localEntity_t    *le;
  75.     refEntity_t        *re;
  76.  
  77.     le = CG_AllocLocalEntity();
  78.     le->leType = LE_LINE;
  79.     le->startTime = cg.time;
  80.     le->endTime = cg.time + time;
  81.     le->lifeRate = 1.0 / ( le->endTime - le->startTime );
  82.  
  83.     re = &le->refEntity;
  84.     VectorCopy( start, re->origin );
  85.     VectorCopy( end, re->oldorigin);
  86.     re->shaderTime = cg.time / 1000.0f;
  87.  
  88.     re->reType = RT_LINE;
  89.     re->radius = 0.5*radius;
  90.     re->customShader = cgs.media.whiteShader; //trap_R_RegisterShaderNoMip("textures/colombia/canvas_doublesided");
  91.  
  92.     re->shaderTexCoord[0] = re->shaderTexCoord[1] = 1.0f;
  93.  
  94.     if (color==0)
  95.     {
  96.         re->shaderRGBA[0] = re->shaderRGBA[1] = re->shaderRGBA[2] = re->shaderRGBA[3] = 0xff;
  97.     }
  98.     else
  99.     {
  100.         re->shaderRGBA[0] = color & 0xff;
  101.         color >>= 8;
  102.         re->shaderRGBA[1] = color & 0xff;
  103.         color >>= 8;
  104.         re->shaderRGBA[2] = color & 0xff;
  105.         re->shaderRGBA[3] = 0xff;
  106.     }
  107.  
  108.     le->color[3] = 1.0;
  109. }
  110.  
  111. /*
  112. ==================
  113. CG_ThrowShard
  114. ==================
  115. */
  116. void CG_ThrowShard( vec3_t origin, vec3_t velocity, qhandle_t hModel ) {
  117.     localEntity_t    *le;
  118.     refEntity_t        *re;
  119.  
  120.     le = CG_AllocLocalEntity();
  121.     re = &le->refEntity;
  122.  
  123.     le->leType = LE_FRAGMENT;
  124.     le->startTime = cg.time;
  125.     le->endTime = le->startTime + 5000 + random() * 3000;
  126.  
  127.     VectorCopy( origin, re->origin );
  128.     AxisCopy( axisDefault, re->axis );
  129.     re->hModel = hModel;
  130.  
  131.     le->pos.trType = TR_GRAVITY;
  132.     le->angles.trType = TR_GRAVITY;
  133.     VectorCopy( origin, le->pos.trBase );
  134.     VectorCopy( velocity, le->pos.trDelta );
  135.     VectorSet(le->angles.trBase, 20, 20, 20);
  136.     VectorCopy( velocity, le->angles.trDelta );
  137.     le->pos.trTime = cg.time;
  138.     le->angles.trTime = cg.time;
  139.  
  140.     le->leFlags = LEF_TUMBLE;
  141.  
  142.     le->angles.trBase[YAW] = 180;
  143.  
  144.     le->bounceFactor = 0.3f;
  145. }
  146.  
  147. /*
  148. ==================
  149. CG_GlassShatter
  150. Throws glass shards from within a given bounding box in the world
  151. ==================
  152. */
  153. void CG_GlassShatter(int entnum, vec3_t org, vec3_t mins, vec3_t maxs)
  154. {
  155.     vec3_t velocity, a, shardorg, dif, difx;
  156.     float windowmass;
  157.     float shardsthrow = 0;
  158.  
  159.     trap_S_StartSound(org, entnum, CHAN_BODY, cgs.media.glassBreakSound, -1, -1 );
  160.  
  161.     VectorSubtract(maxs, mins, a);
  162.  
  163.     windowmass = VectorLength(a); //should give us some idea of how big the chunk of glass is
  164.  
  165.     while (shardsthrow < windowmass)
  166.     {
  167.         velocity[0] = crandom()*150;
  168.         velocity[1] = crandom()*150;
  169.         velocity[2] = 150 + crandom()*75;
  170.  
  171.         VectorCopy(org, shardorg);
  172.     
  173.         dif[0] = (maxs[0]-mins[0])/2;
  174.         dif[1] = (maxs[1]-mins[1])/2;
  175.         dif[2] = (maxs[2]-mins[2])/2;
  176.  
  177.         if (dif[0] < 2)
  178.         {
  179.             dif[0] = 2;
  180.         }
  181.         if (dif[1] < 2)
  182.         {
  183.             dif[1] = 2;
  184.         }
  185.         if (dif[2] < 2)
  186.         {
  187.             dif[2] = 2;
  188.         }
  189.  
  190.         difx[0] = (float) Q_irand(1, (int)((dif[0]*0.9)*2));
  191.         difx[1] = (float) Q_irand(1, (int)((dif[1]*0.9)*2));
  192.         difx[2] = (float) Q_irand(1, (int)((dif[2]*0.9)*2));
  193.  
  194.         if (difx[0] > dif[0])
  195.         {
  196.             shardorg[0] += difx[0]-(dif[0]);
  197.         }
  198.         else
  199.         {
  200.             shardorg[0] -= difx[0];
  201.         }
  202.         if (difx[1] > dif[1])
  203.         {
  204.             shardorg[1] += difx[1]-(dif[1]);
  205.         }
  206.         else
  207.         {
  208.             shardorg[1] -= difx[1];
  209.         }
  210.         if (difx[2] > dif[2])
  211.         {
  212.             shardorg[2] += difx[2]-(dif[2]);
  213.         }
  214.         else
  215.         {
  216.             shardorg[2] -= difx[2];
  217.         }
  218.  
  219.         trap_FX_PlayEffectID( cgs.media.glassChunkEffect, shardorg, velocity, -1, -1 );
  220.  
  221.         shardsthrow += 20;
  222.     }
  223. }
  224.  
  225. qboolean CG_PointLineIntersect ( vec3_t start, vec3_t end, vec3_t point, float rad, vec3_t intersection )
  226. {
  227.     vec3_t dir;
  228.     vec3_t distance;
  229.     float  len;
  230.     float  lineSize;
  231.  
  232.     VectorSubtract ( end, start, dir );
  233.     lineSize = VectorNormalize ( dir );
  234.  
  235.     // Calculate the distnace from the shooter to the target
  236.     VectorSubtract ( point, start, distance );
  237.  
  238.     // Use that distnace to determine the point of tangent in relation to
  239.     // the center of the player entity
  240.     VectorMA ( start, DotProduct ( dir, distance ), dir, intersection );
  241.  
  242.     VectorSubtract ( intersection, point, distance );
  243.     len = VectorLengthSquared ( distance );
  244.  
  245.     // Is the intersection point within the given radius requirements?
  246.     if ( len < rad * rad )
  247.     {
  248.         // Make sure its not past the end of the given line
  249.         VectorSubtract ( intersection, start, distance );
  250.         len = VectorLengthSquared ( distance );
  251.  
  252.         // If the len
  253.         if ( len < lineSize * lineSize )
  254.         {
  255.             return qtrue;
  256.         }
  257.     }
  258.  
  259.     return qfalse;
  260. }
  261.  
  262. void CG_BulletFlyBySound ( vec3_t start, vec3_t end )
  263. {
  264.     // make the incidental sounds - all of these should already be precached on the server
  265.     vec3_t    soundPoint;
  266.     if( CG_PointLineIntersect(start, end, cg.refdef.vieworg, 100, soundPoint ) )
  267.     {
  268.         if (irand(1, 10) < 5)
  269.         {
  270.             int which = irand(0, NUMFLYBYS - 1);
  271.             
  272.             trap_S_StartSound (soundPoint, cg.predictedPlayerState.clientNum, CHAN_AUTO, cgs.media.flybySounds[which], -1, -1 );
  273.         }
  274.     }
  275. }
  276.